//
//  Json2Object.m
//  rrdTK
//
//  Created by yangaichun on 16/2/1.
//  Copyright © 2016年 com.weiba66. All rights reserved.
//

#import "JsonConverter.h"

@implementation JsonConverter

//jsonString 转对象
+(id)jsonStr2Object:(NSString *)jsonStr{
    
    if (!jsonStr ||[jsonStr isEqualToString:@""]) {
        return  nil;
    }
    //系统自带JSON解析
    NSData *tmp = [jsonStr dataUsingEncoding:NSUTF8StringEncoding];
    return [NSJSONSerialization JSONObjectWithData:tmp options:NSJSONReadingMutableLeaves error:nil];
}


//对象转jsonString
+(NSString *)object2JsonStr:(id)object{
    if (object == nil) {
        return nil;
    }
    
    if (![NSJSONSerialization isValidJSONObject:object]) {
        return nil;
    }
    
    NSData *tmp = [NSJSONSerialization dataWithJSONObject:object options:0 error:nil];
    
    return [[NSString alloc]initWithData:tmp encoding:NSUTF8StringEncoding];
}



@end
